package com.cs.paoyer.common.exception;

import com.cs.paoyer.common.exception.CommonSystemException;
import com.cs.paoyer.common.exception.CommonUserException;
import com.cs.paoyer.common.exception.SystemException;
import com.cs.paoyer.common.exception.UserException;

import java.sql.SQLException;

public class OracleKnownException {

  public OracleKnownException()
  {
  }

  public static void traslateSQLException ( SQLException se ) 
    throws UserException, SystemException {
    
    switch ( se.getErrorCode() ) {
      case 1: 
        throw new UserException( new CommonUserException().getModuleVO(),
          CommonUserException.DUPLICATE_PRIMARY_KEY);
      case 1401: 
        throw new UserException( new CommonUserException().getModuleVO(),
          CommonUserException.VALUE_TOO_LARGE);
      case 2292: 
        throw new UserException( new CommonUserException().getModuleVO(),
          CommonUserException.ANOTHER_RECORD_ASOCIATED);

      case 20101: 
        throw new UserException( new CommonUserException().getModuleVO(),
          CommonUserException.INVALID_VALUE_FOR_MAIN_OPTION);
          
      default:
        throw new SystemException( new CommonSystemException().getModuleVO(), 
          CommonSystemException.QUERY_EXCEPTION, se, se.getMessage() );
    }
    
  }

}